﻿using System;

namespace CSharp_1209
{
    public delegate int Calculation();
    public delegate void FinishHandler();

    class Mathematics
    {
        public Calculation Multiply; // delegate
        public event FinishHandler Finish; // event

        public int NumOne { get; set; }
        public int NumTwo { get; set; }

        public int Addition()
        {
            int total = NumOne + NumTwo;
            Console.WriteLine("Addition = {0}", total);

            if (Finish != null)
                Finish();

            return total;
        }

        public int Subtraction()
        {
            int sub = NumOne - NumTwo;
            Console.WriteLine("Subtraction = {0}", sub);

            return sub;
        }

        public static void Test()
        {
            Mathematics m = new Mathematics();

            m.NumOne = 5;
            m.NumTwo = 23;

            Calculation c = m.Addition;
            c += m.Subtraction;
            //c -= m.Addition;

            m.Finish = delegate()
                           {
                               Console.WriteLine("Finish all");
                           };
            c();

            m.Multiply += delegate()
            {
                int multiply = m.NumOne * m.NumTwo;
                Console.WriteLine("Multiply = {0}", multiply);
                return multiply;
            };
            m.Multiply();
        }
    }
}
